// ---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "formatthread.h"
#include "vdskapi.h"
#include "main.h"
#include "functions.h"
#pragma package(smart_init)
extern HANDLE hdisk;
extern TForm1 *Form1;
// ---------------------------------------------------------------------------

// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(&UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall formatthread::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
// ---------------------------------------------------------------------------

__fastcall formatthread::formatthread(bool CreateSuspended):TThread(CreateSuspended)
{
}

// ---------------------------------------------------------------------------
void __fastcall formatthread::Execute()
{
    NameThreadForDebugging("formatthread");
    // ---- Place thread code here ----

    VdskUnmountDisk(hdisk, 'y');
    unsigned long clstsize = 4096;
    int ret = VdskFormatDisk(hdisk, VDSK_FS_FAT , "temp1", false, clstsize, OnFormat, NULL);
    if (!ret)
    {
        deb("VdskFormatDisk: %s", fmterr());
    }
    else
    {
        deb("successfully formated disk");
    }
   // MessageBox(NULL, "format done", NULL, MB_OK);
        Form1->Button3->Enabled=true;
        VdskMountDisk(hdisk, 'y', true);
}
// ---------------------------------------------------------------------------
